require "spec_helper"

RSpec.describe Endpoints::<%= plural_class_name %> do
  include Committee::Test::Methods
  include Rack::Test::Methods

  def app
    Routes
  end

  def schema_path
    "./schema/schema.json"
  end

  before do
    @<%= field_name %> = <%= singular_class_name %>.create

    # temporarily touch #updated_at until we can fix prmd
    @<%= field_name %>.updated_at
    @<%= field_name %>.save
  end

  describe 'GET <%= url_path %>' do
    it 'returns correct status code and conforms to schema' do
      get '<%= url_path %>'
      assert_equal 200, last_response.status
      assert_schema_conform
    end
  end

=begin
  describe 'POST <%= url_path %>' do
    it 'returns correct status code and conforms to schema' do
      header "Content-Type", "application/json"
      post '<%= url_path %>', MultiJson.encode({})
      assert_equal 201, last_response.status
      assert_schema_conform
    end
  end
=end

  describe 'GET <%= url_path %>/:id' do
    it 'returns correct status code and conforms to schema' do
      get "<%= url_path %>/#{@<%= field_name %>.id}"
      assert_equal 200, last_response.status
      assert_schema_conform
    end
  end

  describe 'PATCH <%= url_path %>/:id' do
    it 'returns correct status code and conforms to schema' do
      header "Content-Type", "application/json"
      patch "<%= url_path %>/#{@<%= field_name %>.id}", MultiJson.encode({})
      assert_equal 200, last_response.status
      assert_schema_conform
    end
  end

  describe 'DELETE <%= url_path %>/:id' do
    it 'returns correct status code and conforms to schema' do
      delete "<%= url_path %>/#{@<%= field_name %>.id}"
      assert_equal 200, last_response.status
      assert_schema_conform
    end
  end
end
